package org.dubnation.auth.controller;

import org.dubnation.base.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/logout")
public class LogoutController {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @DeleteMapping
    public AjaxResult deleteToken(HttpServletRequest request) {
        String token = request.getHeader("token");
        redisTemplate.delete(token);
        return AjaxResult.me();
    }
}
